﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Jalal.Library.Data;
using System.Data.Common;
using Jalal.Library.Utility;

namespace BCGC.DAL
{
    public class ResourceData
    {
        public static DataTable GetAllCheatCodes(int currentPageIndex, string sortOrder,
            int pageSize, string searchTitle, string searchGameTitle, DateTime? searchCreateDateFrom,
            DateTime? searchCreateDateTo, bool? searchActive, out int totalData)
        {
            totalData = 0;
            object count = null;

            DataMiner dataMiner = DataFactory.GetDataMiner();
            DbCommand command = DataFactory.GetCommand();

            dataMiner.AddParameter(command, "@CurrentPageIndex", DbType.Int32, 0, ParameterDirection.Input, currentPageIndex);
            dataMiner.AddParameter(command, "@SortOrder", DbType.String, 500, ParameterDirection.Input, sortOrder);
            dataMiner.AddParameter(command, "@PageSize", DbType.Int32, 0, ParameterDirection.Input, pageSize);
            dataMiner.AddParameter(command, "@SearchTitle", DbType.String, 2000, ParameterDirection.Input, searchTitle);
            dataMiner.AddParameter(command, "@SearchGameTitle", DbType.String, 2000, ParameterDirection.Input, searchGameTitle);
            dataMiner.AddParameter(command, "@SearchCreateDateFrom", DbType.DateTime, 0, ParameterDirection.Input, searchCreateDateFrom);
            dataMiner.AddParameter(command, "@SearchCreateDateTo", DbType.DateTime, 0, ParameterDirection.Input, searchCreateDateTo);
            dataMiner.AddParameter(command, "@SearchActive", DbType.Boolean, 0, ParameterDirection.Input, searchActive);

            command.CommandText = "CSP_GetTotalCheatCodeCount";
            count = dataMiner.GetOneData(command);
            totalData = (int)CommonUtility.FilterNull(count, typeof(int));

            command.CommandText = "CSP_GetCheatCodeList";
            return dataMiner.GetListData(command);
        }

        public static DataTable GetCheatCodesByGame(int currentPageIndex, string sortOrder, int pageSize,
            string title, int gameId, out int totalData)
        {
            totalData = 0;
            object count = null;

            DataMiner dataMiner = DataFactory.GetDataMiner();
            DbCommand command = DataFactory.GetCommand();

            dataMiner.AddParameter(command, "@CurrentPageIndex", DbType.Int32, 0, ParameterDirection.Input, currentPageIndex);
            dataMiner.AddParameter(command, "@SortOrder", DbType.String, 500, ParameterDirection.Input, sortOrder);
            dataMiner.AddParameter(command, "@PageSize", DbType.Int32, 0, ParameterDirection.Input, pageSize);
            dataMiner.AddParameter(command, "@SearchTitle", DbType.String, 2000, ParameterDirection.Input, title);
            dataMiner.AddParameter(command, "@SearchGameId", DbType.Int32, 0, ParameterDirection.Input, gameId);

            command.CommandText = "CSP_GetTotalCheatCodeCountByGameId";
            count = dataMiner.GetOneData(command);
            totalData = (int)CommonUtility.FilterNull(count, typeof(int));

            command.CommandText = "CSP_GetCheatCodeListByGameId";
            return dataMiner.GetListData(command);
        }

        public static int CreateNewCheatCode(string title, int gameId, string description, 
            string cheatCodeDetail, bool isActive)
        {
            object id = null;
            DataMiner dataMiner = DataFactory.GetDataMiner();
            DbCommand command = DataFactory.GetCommand();
            command.CommandText = "CSP_CreateNewCheatCode";
            dataMiner.AddParameter(command, "@Title", DbType.String, 2000, ParameterDirection.Input, title);
            dataMiner.AddParameter(command, "@GameId", DbType.Int32, 0, ParameterDirection.Input, gameId);
            dataMiner.AddParameter(command, "@Description", DbType.String, -1, ParameterDirection.Input, description);
            dataMiner.AddParameter(command, "@CheatCodeDetail", DbType.String, -1, ParameterDirection.Input, cheatCodeDetail);
            dataMiner.AddParameter(command, "@IsActive", DbType.Boolean, 0, ParameterDirection.Input, isActive);
            dataMiner.AddParameter(command, "ReturnValue", DbType.Int32, 0, ParameterDirection.ReturnValue, null);
            dataMiner.Execute(command, out id);

            return (int)CommonUtility.FilterNull(id, typeof(int));
        }

        public static int DeleteCheatCodes(List<int> cheatCodesToDelete)
        {
            object count = null;
            DataMiner dataMiner = DataFactory.GetDataMiner();
            DbCommand command = DataFactory.GetCommand();
            command.CommandText = "CSP_DeleteCheatCodes";
            dataMiner.AddParameter(command, "@Ids", DbType.String, -1, ParameterDirection.Input, DataMiner.FormatXMLForIdArray(cheatCodesToDelete));
            dataMiner.AddParameter(command, "ReturnValue", DbType.Int32, 0, ParameterDirection.ReturnValue, null);
            dataMiner.Execute(command, out count);

            return (int)CommonUtility.FilterNull(count, typeof(int));
        }

        public static int UpdateActiveCheatCode(List<int> activeCheatCodes, List<int> inactiveCheatCodes)
        {
            object count = null;
            DataMiner dataMiner = DataFactory.GetDataMiner();
            DbCommand command = DataFactory.GetCommand();
            command.CommandText = "CSP_UpdateActiveCheatCode";
            dataMiner.AddParameter(command, "@CheatCodeIdsToActive", DbType.String, -1, ParameterDirection.Input, DataMiner.FormatXMLForIdArray(activeCheatCodes));
            dataMiner.AddParameter(command, "@CheatCodeIdsToInactive", DbType.String, -1, ParameterDirection.Input, DataMiner.FormatXMLForIdArray(inactiveCheatCodes));
            dataMiner.AddParameter(command, "ReturnValue", DbType.Int32, 0, ParameterDirection.ReturnValue, null);
            dataMiner.Execute(command, out count);

            return (int)CommonUtility.FilterNull(count, typeof(int));
        }

        public static int UpdateCheatCode(int id, string title, int gameId, string description, 
            string cheatCodeDetail, bool isActive)
        {
            object count = null;
            DataMiner dataMiner = DataFactory.GetDataMiner();
            DbCommand command = DataFactory.GetCommand();
            command.CommandText = "CSP_UpdateCheatCode";
            dataMiner.AddParameter(command, "@CheatCodeId", DbType.Int32, 0, ParameterDirection.Input, id);
            dataMiner.AddParameter(command, "@Title", DbType.String, -1, ParameterDirection.Input, title);
            dataMiner.AddParameter(command, "@GameId", DbType.Int32, 0, ParameterDirection.Input, gameId);
            dataMiner.AddParameter(command, "@Description", DbType.String, -1, ParameterDirection.Input, description);
            dataMiner.AddParameter(command, "@CheatCodeDetail", DbType.String, -1, ParameterDirection.Input, cheatCodeDetail);
            dataMiner.AddParameter(command, "@IsActive", DbType.Boolean, 0, ParameterDirection.Input, isActive);
            dataMiner.AddParameter(command, "ReturnValue", DbType.Int32, 0, ParameterDirection.ReturnValue, null);
            dataMiner.Execute(command, out count);

            return (int)CommonUtility.FilterNull(count, typeof(int));
        }

        public static DataTable GetCheatCodeById(int id)
        {
            DataMiner dataMiner = DataFactory.GetDataMiner();
            DbCommand command = DataFactory.GetCommand();
            command.CommandText = "CSP_GetCheatCodeById";
            dataMiner.AddParameter(command, "@CheatCodeId", DbType.Int32, 0, ParameterDirection.Input, id);
            return dataMiner.GetListData(command);
        }

        /**************************************************************
         *      Crack items
         *************************************************************/
        public static int CreateNewCrack(string title, int gameId, string description, 
            string fileUrl, bool isActive)
        {
            object id = null;
            DataMiner dataMiner = DataFactory.GetDataMiner();
            DbCommand command = DataFactory.GetCommand();
            command.CommandText = "CSP_CreateNewCrack";
            dataMiner.AddParameter(command, "@Title", DbType.String, 2000, ParameterDirection.Input, title);
            dataMiner.AddParameter(command, "@GameId", DbType.Int32, 0, ParameterDirection.Input, gameId);
            dataMiner.AddParameter(command, "@Description", DbType.String, -1, ParameterDirection.Input, description);
            dataMiner.AddParameter(command, "@FileUrl", DbType.String, -1, ParameterDirection.Input, fileUrl);
            dataMiner.AddParameter(command, "@IsActive", DbType.Boolean, 0, ParameterDirection.Input, isActive);
            dataMiner.AddParameter(command, "ReturnValue", DbType.Int32, 0, ParameterDirection.ReturnValue, null);
            dataMiner.Execute(command, out id);

            return (int)CommonUtility.FilterNull(id, typeof(int));
        }

        public static int DeleteCracks(List<int> patchsToDelete)
        {
            object count = null;
            DataMiner dataMiner = DataFactory.GetDataMiner();
            DbCommand command = DataFactory.GetCommand();
            command.CommandText = "CSP_DeleteCracks";
            dataMiner.AddParameter(command, "@Ids", DbType.String, -1, ParameterDirection.Input, DataMiner.FormatXMLForIdArray(patchsToDelete));
            dataMiner.AddParameter(command, "ReturnValue", DbType.Int32, 0, ParameterDirection.ReturnValue, null);
            dataMiner.Execute(command, out count);

            return (int)CommonUtility.FilterNull(count, typeof(int));
        }

        public static int UpdateActiveCrack(List<int> activeCracks, List<int> inactiveCracks)
        {
            object count = null;
            DataMiner dataMiner = DataFactory.GetDataMiner();
            DbCommand command = DataFactory.GetCommand();
            command.CommandText = "CSP_UpdateActiveCrack";
            dataMiner.AddParameter(command, "@CrackIdsToActive", DbType.String, -1, ParameterDirection.Input, DataMiner.FormatXMLForIdArray(activeCracks));
            dataMiner.AddParameter(command, "@CrackIdsToInactive", DbType.String, -1, ParameterDirection.Input, DataMiner.FormatXMLForIdArray(inactiveCracks));
            dataMiner.AddParameter(command, "ReturnValue", DbType.Int32, 0, ParameterDirection.ReturnValue, null);
            dataMiner.Execute(command, out count);

            return (int)CommonUtility.FilterNull(count, typeof(int));
        }

        public static DataTable GetAllCracks(int currentPageIndex, string sortOrder, 
            int pageSize, string searchTitle, string searchGameTitle, DateTime? searchCreateDateFrom, 
            DateTime? searchCreateDateTo, bool? searchActive, out int totalData)
        {
            totalData = 0;
            object count = null;

            DataMiner dataMiner = DataFactory.GetDataMiner();
            DbCommand command = DataFactory.GetCommand();

            dataMiner.AddParameter(command, "@CurrentPageIndex", DbType.Int32, 0, ParameterDirection.Input, currentPageIndex);
            dataMiner.AddParameter(command, "@SortOrder", DbType.String, 500, ParameterDirection.Input, sortOrder);
            dataMiner.AddParameter(command, "@PageSize", DbType.Int32, 0, ParameterDirection.Input, pageSize);
            dataMiner.AddParameter(command, "@SearchTitle", DbType.String, 2000, ParameterDirection.Input, searchTitle);
            dataMiner.AddParameter(command, "@SearchGameTitle", DbType.String, 2000, ParameterDirection.Input, searchGameTitle);
            dataMiner.AddParameter(command, "@SearchCreateDateFrom", DbType.DateTime, 0, ParameterDirection.Input, searchCreateDateFrom);
            dataMiner.AddParameter(command, "@SearchCreateDateTo", DbType.DateTime, 0, ParameterDirection.Input, searchCreateDateTo);
            dataMiner.AddParameter(command, "@SearchActive", DbType.Boolean, 0, ParameterDirection.Input, searchActive);

            command.CommandText = "CSP_GetTotalCrackCount";
            count = dataMiner.GetOneData(command);
            totalData = (int)CommonUtility.FilterNull(count, typeof(int));

            command.CommandText = "CSP_GetCrackList";
            return dataMiner.GetListData(command);
        }

        public static DataTable GetCracksByGame(int currentPageIndex, string sortOrder, 
            int pageSize, string title, int gameId, out int totalData)
        {
            totalData = 0;
            object count = null;

            DataMiner dataMiner = DataFactory.GetDataMiner();
            DbCommand command = DataFactory.GetCommand();

            dataMiner.AddParameter(command, "@CurrentPageIndex", DbType.Int32, 0, ParameterDirection.Input, currentPageIndex);
            dataMiner.AddParameter(command, "@SortOrder", DbType.String, 500, ParameterDirection.Input, sortOrder);
            dataMiner.AddParameter(command, "@PageSize", DbType.Int32, 0, ParameterDirection.Input, pageSize);
            dataMiner.AddParameter(command, "@SearchTitle", DbType.String, 2000, ParameterDirection.Input, title);
            dataMiner.AddParameter(command, "@SearchGameId", DbType.Int32, 0, ParameterDirection.Input, gameId);

            command.CommandText = "CSP_GetTotalCrackCountByGameId";
            count = dataMiner.GetOneData(command);
            totalData = (int)CommonUtility.FilterNull(count, typeof(int));

            command.CommandText = "CSP_GetCrackListByGameId";
            return dataMiner.GetListData(command);
        }

        public static DataTable GetCrackFileLocationsToForDelete(List<int> cracksToDelete)
        {
            DataMiner dataMiner = DataFactory.GetDataMiner();
            DbCommand command = DataFactory.GetCommand();
            command.CommandText = "CSP_GetCrackFileLocationsByIds";
            dataMiner.AddParameter(command, "@Ids", DbType.String, -1, ParameterDirection.Input, DataMiner.FormatXMLForIdArray(cracksToDelete));
            return dataMiner.GetListData(command);
        }

        public static DataTable GetCrackById(int id)
        {
            DataMiner dataMiner = DataFactory.GetDataMiner();
            DbCommand command = DataFactory.GetCommand();
            command.CommandText = "CSP_GetCrackById";
            dataMiner.AddParameter(command, "@CrackId", DbType.Int32, 0, ParameterDirection.Input, id);
            return dataMiner.GetListData(command);
        }

        public static int UpdateCrack(int id, string title, int gameId, string description, 
            string fileUrl, bool isActive)
        {
            object count = null;
            DataMiner dataMiner = DataFactory.GetDataMiner();
            DbCommand command = DataFactory.GetCommand();
            command.CommandText = "CSP_UpdateCrack";
            dataMiner.AddParameter(command, "@CrackId", DbType.Int32, 0, ParameterDirection.Input, id);
            dataMiner.AddParameter(command, "@Title", DbType.String, -1, ParameterDirection.Input, title);
            dataMiner.AddParameter(command, "@GameId", DbType.Int32, 0, ParameterDirection.Input, gameId);
            dataMiner.AddParameter(command, "@Description", DbType.String, -1, ParameterDirection.Input, description);
            dataMiner.AddParameter(command, "@FileUrl", DbType.String, -1, ParameterDirection.Input, fileUrl);
            dataMiner.AddParameter(command, "@IsActive", DbType.Boolean, 0, ParameterDirection.Input, isActive);
            dataMiner.AddParameter(command, "ReturnValue", DbType.Int32, 0, ParameterDirection.ReturnValue, null);
            dataMiner.Execute(command, out count);

            return (int)CommonUtility.FilterNull(count, typeof(int));
        }


        /**************************************************************
         *      Patch items
         *************************************************************/
        public static int CreateNewPatch(string title, int gameId, string description,
            string fileUrl, bool isActive)
        {
            object id = null;
            DataMiner dataMiner = DataFactory.GetDataMiner();
            DbCommand command = DataFactory.GetCommand();
            command.CommandText = "CSP_CreateNewPatch";
            dataMiner.AddParameter(command, "@Title", DbType.String, 2000, ParameterDirection.Input, title);
            dataMiner.AddParameter(command, "@GameId", DbType.Int32, 0, ParameterDirection.Input, gameId);
            dataMiner.AddParameter(command, "@Description", DbType.String, -1, ParameterDirection.Input, description);
            dataMiner.AddParameter(command, "@FileUrl", DbType.String, -1, ParameterDirection.Input, fileUrl);
            dataMiner.AddParameter(command, "@IsActive", DbType.Boolean, 0, ParameterDirection.Input, isActive);
            dataMiner.AddParameter(command, "ReturnValue", DbType.Int32, 0, ParameterDirection.ReturnValue, null);
            dataMiner.Execute(command, out id);

            return (int)CommonUtility.FilterNull(id, typeof(int));
        }

        public static int DeletePatches(List<int> patchesToDelete)
        {
            object count = null;
            DataMiner dataMiner = DataFactory.GetDataMiner();
            DbCommand command = DataFactory.GetCommand();
            command.CommandText = "CSP_DeletePatches";
            dataMiner.AddParameter(command, "@Ids", DbType.String, -1, ParameterDirection.Input, DataMiner.FormatXMLForIdArray(patchesToDelete));
            dataMiner.AddParameter(command, "ReturnValue", DbType.Int32, 0, ParameterDirection.ReturnValue, null);
            dataMiner.Execute(command, out count);

            return (int)CommonUtility.FilterNull(count, typeof(int));
        }

        public static int UpdateActivePatch(List<int> activePatches, List<int> inactivePatches)
        {
            object count = null;
            DataMiner dataMiner = DataFactory.GetDataMiner();
            DbCommand command = DataFactory.GetCommand();
            command.CommandText = "CSP_UpdateActivePatch";
            dataMiner.AddParameter(command, "@PatchIdsToActive", DbType.String, -1, ParameterDirection.Input, DataMiner.FormatXMLForIdArray(activePatches));
            dataMiner.AddParameter(command, "@PatchIdsToInactive", DbType.String, -1, ParameterDirection.Input, DataMiner.FormatXMLForIdArray(inactivePatches));
            dataMiner.AddParameter(command, "ReturnValue", DbType.Int32, 0, ParameterDirection.ReturnValue, null);
            dataMiner.Execute(command, out count);

            return (int)CommonUtility.FilterNull(count, typeof(int));
        }

        public static DataTable GetAllPatches(int currentPageIndex, string sortOrder,
            int pageSize, string searchTitle, string searchGameTitle, DateTime? searchCreateDateFrom,
            DateTime? searchCreateDateTo, bool? searchActive, out int totalData)
        {
            totalData = 0;
            object count = null;

            DataMiner dataMiner = DataFactory.GetDataMiner();
            DbCommand command = DataFactory.GetCommand();

            dataMiner.AddParameter(command, "@CurrentPageIndex", DbType.Int32, 0, ParameterDirection.Input, currentPageIndex);
            dataMiner.AddParameter(command, "@SortOrder", DbType.String, 500, ParameterDirection.Input, sortOrder);
            dataMiner.AddParameter(command, "@PageSize", DbType.Int32, 0, ParameterDirection.Input, pageSize);
            dataMiner.AddParameter(command, "@SearchTitle", DbType.String, 2000, ParameterDirection.Input, searchTitle);
            dataMiner.AddParameter(command, "@SearchGameTitle", DbType.String, 2000, ParameterDirection.Input, searchGameTitle);
            dataMiner.AddParameter(command, "@SearchCreateDateFrom", DbType.DateTime, 0, ParameterDirection.Input, searchCreateDateFrom);
            dataMiner.AddParameter(command, "@SearchCreateDateTo", DbType.DateTime, 0, ParameterDirection.Input, searchCreateDateTo);
            dataMiner.AddParameter(command, "@SearchActive", DbType.Boolean, 0, ParameterDirection.Input, searchActive);

            command.CommandText = "CSP_GetTotalPatchCount";
            count = dataMiner.GetOneData(command);
            totalData = (int)CommonUtility.FilterNull(count, typeof(int));

            command.CommandText = "CSP_GetPatchList";
            return dataMiner.GetListData(command);
        }

        public static DataTable GetPatchFileLocationsToForDelete(List<int> patchesToDelete)
        {
            DataMiner dataMiner = DataFactory.GetDataMiner();
            DbCommand command = DataFactory.GetCommand();
            command.CommandText = "CSP_GetPatchFileLocationsByIds";
            dataMiner.AddParameter(command, "@Ids", DbType.String, -1, ParameterDirection.Input, DataMiner.FormatXMLForIdArray(patchesToDelete));
            return dataMiner.GetListData(command);
        }

        public static DataTable GetPatchById(int id)
        {
            DataMiner dataMiner = DataFactory.GetDataMiner();
            DbCommand command = DataFactory.GetCommand();
            command.CommandText = "CSP_GetPatchById";
            dataMiner.AddParameter(command, "@PatchId", DbType.Int32, 0, ParameterDirection.Input, id);
            return dataMiner.GetListData(command);
        }

        public static int UpdatePatch(int id, string title, int gameId, string description,
            string fileUrl, bool isActive)
        {
            object count = null;
            DataMiner dataMiner = DataFactory.GetDataMiner();
            DbCommand command = DataFactory.GetCommand();
            command.CommandText = "CSP_UpdatePatch";
            dataMiner.AddParameter(command, "@PatchId", DbType.Int32, 0, ParameterDirection.Input, id);
            dataMiner.AddParameter(command, "@Title", DbType.String, -1, ParameterDirection.Input, title);
            dataMiner.AddParameter(command, "@GameId", DbType.Int32, 0, ParameterDirection.Input, gameId);
            dataMiner.AddParameter(command, "@Description", DbType.String, -1, ParameterDirection.Input, description);
            dataMiner.AddParameter(command, "@FileUrl", DbType.String, -1, ParameterDirection.Input, fileUrl);
            dataMiner.AddParameter(command, "@IsActive", DbType.Boolean, 0, ParameterDirection.Input, isActive);
            dataMiner.AddParameter(command, "ReturnValue", DbType.Int32, 0, ParameterDirection.ReturnValue, null);
            dataMiner.Execute(command, out count);

            return (int)CommonUtility.FilterNull(count, typeof(int));
        }

        /**************************************************************
         *      Trial items
         *************************************************************/
        public static int CreateNewTrial(string title, int gameId, string description,
            string fileUrl, bool isActive)
        {
            object id = null;
            DataMiner dataMiner = DataFactory.GetDataMiner();
            DbCommand command = DataFactory.GetCommand();
            command.CommandText = "CSP_CreateNewTrial";
            dataMiner.AddParameter(command, "@Title", DbType.String, 2000, ParameterDirection.Input, title);
            dataMiner.AddParameter(command, "@GameId", DbType.Int32, 0, ParameterDirection.Input, gameId);
            dataMiner.AddParameter(command, "@Description", DbType.String, -1, ParameterDirection.Input, description);
            dataMiner.AddParameter(command, "@FileUrl", DbType.String, -1, ParameterDirection.Input, fileUrl);
            dataMiner.AddParameter(command, "@IsActive", DbType.Boolean, 0, ParameterDirection.Input, isActive);
            dataMiner.AddParameter(command, "ReturnValue", DbType.Int32, 0, ParameterDirection.ReturnValue, null);
            dataMiner.Execute(command, out id);

            return (int)CommonUtility.FilterNull(id, typeof(int));
        }

        public static int DeleteTrials(List<int> trailsToDelete)
        {
            object count = null;
            DataMiner dataMiner = DataFactory.GetDataMiner();
            DbCommand command = DataFactory.GetCommand();
            command.CommandText = "CSP_DeleteTrials";
            dataMiner.AddParameter(command, "@Ids", DbType.String, -1, ParameterDirection.Input, DataMiner.FormatXMLForIdArray(trailsToDelete));
            dataMiner.AddParameter(command, "ReturnValue", DbType.Int32, 0, ParameterDirection.ReturnValue, null);
            dataMiner.Execute(command, out count);

            return (int)CommonUtility.FilterNull(count, typeof(int));
        }

        public static int UpdateActiveTrial(List<int> activeTrials, List<int> inactiveTrials)
        {
            object count = null;
            DataMiner dataMiner = DataFactory.GetDataMiner();
            DbCommand command = DataFactory.GetCommand();
            command.CommandText = "CSP_UpdateActiveTrial";
            dataMiner.AddParameter(command, "@TrialIdsToActive", DbType.String, -1, ParameterDirection.Input, DataMiner.FormatXMLForIdArray(activeTrials));
            dataMiner.AddParameter(command, "@TrialIdsToInactive", DbType.String, -1, ParameterDirection.Input, DataMiner.FormatXMLForIdArray(inactiveTrials));
            dataMiner.AddParameter(command, "ReturnValue", DbType.Int32, 0, ParameterDirection.ReturnValue, null);
            dataMiner.Execute(command, out count);

            return (int)CommonUtility.FilterNull(count, typeof(int));
        }

        public static DataTable GetAllTrials(int currentPageIndex, string sortOrder,
            int pageSize, string searchTitle, string searchGameTitle, DateTime? searchCreateDateFrom,
            DateTime? searchCreateDateTo, bool? searchActive, out int totalData)
        {
            totalData = 0;
            object count = null;

            DataMiner dataMiner = DataFactory.GetDataMiner();
            DbCommand command = DataFactory.GetCommand();

            dataMiner.AddParameter(command, "@CurrentPageIndex", DbType.Int32, 0, ParameterDirection.Input, currentPageIndex);
            dataMiner.AddParameter(command, "@SortOrder", DbType.String, 500, ParameterDirection.Input, sortOrder);
            dataMiner.AddParameter(command, "@PageSize", DbType.Int32, 0, ParameterDirection.Input, pageSize);
            dataMiner.AddParameter(command, "@SearchTitle", DbType.String, 2000, ParameterDirection.Input, searchTitle);
            dataMiner.AddParameter(command, "@SearchGameTitle", DbType.String, 2000, ParameterDirection.Input, searchGameTitle);
            dataMiner.AddParameter(command, "@SearchCreateDateFrom", DbType.DateTime, 0, ParameterDirection.Input, searchCreateDateFrom);
            dataMiner.AddParameter(command, "@SearchCreateDateTo", DbType.DateTime, 0, ParameterDirection.Input, searchCreateDateTo);
            dataMiner.AddParameter(command, "@SearchActive", DbType.Boolean, 0, ParameterDirection.Input, searchActive);

            command.CommandText = "CSP_GetTotalTrialCount";
            count = dataMiner.GetOneData(command);
            totalData = (int)CommonUtility.FilterNull(count, typeof(int));

            command.CommandText = "CSP_GetTrialList";
            return dataMiner.GetListData(command);
        }

        public static DataTable GetTrialFileLocationsToForDelete(List<int> trailsToDelete)
        {
            DataMiner dataMiner = DataFactory.GetDataMiner();
            DbCommand command = DataFactory.GetCommand();
            command.CommandText = "CSP_GetTrialFileLocationsByIds";
            dataMiner.AddParameter(command, "@Ids", DbType.String, -1, ParameterDirection.Input, DataMiner.FormatXMLForIdArray(trailsToDelete));
            return dataMiner.GetListData(command);
        }

        public static DataTable GetTrialById(int id)
        {
            DataMiner dataMiner = DataFactory.GetDataMiner();
            DbCommand command = DataFactory.GetCommand();
            command.CommandText = "CSP_GetTrialById";
            dataMiner.AddParameter(command, "@TrialId", DbType.Int32, 0, ParameterDirection.Input, id);
            return dataMiner.GetListData(command);
        }

        public static int UpdateTrial(int id, string title, int gameId, string description,
            string fileUrl, bool isActive)
        {
            object count = null;
            DataMiner dataMiner = DataFactory.GetDataMiner();
            DbCommand command = DataFactory.GetCommand();
            command.CommandText = "CSP_UpdateTrial";
            dataMiner.AddParameter(command, "@TrialId", DbType.Int32, 0, ParameterDirection.Input, id);
            dataMiner.AddParameter(command, "@Title", DbType.String, -1, ParameterDirection.Input, title);
            dataMiner.AddParameter(command, "@GameId", DbType.Int32, 0, ParameterDirection.Input, gameId);
            dataMiner.AddParameter(command, "@Description", DbType.String, -1, ParameterDirection.Input, description);
            dataMiner.AddParameter(command, "@FileUrl", DbType.String, -1, ParameterDirection.Input, fileUrl);
            dataMiner.AddParameter(command, "@IsActive", DbType.Boolean, 0, ParameterDirection.Input, isActive);
            dataMiner.AddParameter(command, "ReturnValue", DbType.Int32, 0, ParameterDirection.ReturnValue, null);
            dataMiner.Execute(command, out count);

            return (int)CommonUtility.FilterNull(count, typeof(int));
        }

        /**************************************************************
         *      Trailer items
         *************************************************************/
        public static int CreateNewTrailer(string title, int gameId, string description,
            string fileUrl, string thumbnailImageUrl, string previewImageUrl, int width, int height, bool isActive)
        {
            object id = null;
            DataMiner dataMiner = DataFactory.GetDataMiner();
            DbCommand command = DataFactory.GetCommand();
            command.CommandText = "CSP_CreateNewTrailer";
            dataMiner.AddParameter(command, "@Title", DbType.String, 2000, ParameterDirection.Input, title);
            dataMiner.AddParameter(command, "@GameId", DbType.Int32, 0, ParameterDirection.Input, gameId);
            dataMiner.AddParameter(command, "@Description", DbType.String, -1, ParameterDirection.Input, description);
            dataMiner.AddParameter(command, "@FileUrl", DbType.String, -1, ParameterDirection.Input, fileUrl);
            dataMiner.AddParameter(command, "@ThumbnailImageUrl", DbType.String, -1, ParameterDirection.Input, thumbnailImageUrl);
            dataMiner.AddParameter(command, "@PreviewImageUrl", DbType.String, -1, ParameterDirection.Input, previewImageUrl);
            dataMiner.AddParameter(command, "@IsActive", DbType.Boolean, 0, ParameterDirection.Input, isActive);
            dataMiner.AddParameter(command, "@Width", DbType.Int32, 0, ParameterDirection.Input, width);
            dataMiner.AddParameter(command, "@Height", DbType.Int32, 0, ParameterDirection.Input, height);
            dataMiner.AddParameter(command, "ReturnValue", DbType.Int32, 0, ParameterDirection.ReturnValue, null);
            dataMiner.Execute(command, out id);

            return (int)CommonUtility.FilterNull(id, typeof(int));
        }

        public static int DeleteTrailers(List<int> trailersToDelete)
        {
            object count = null;
            DataMiner dataMiner = DataFactory.GetDataMiner();
            DbCommand command = DataFactory.GetCommand();
            command.CommandText = "CSP_DeleteTrailers";
            dataMiner.AddParameter(command, "@Ids", DbType.String, -1, ParameterDirection.Input, DataMiner.FormatXMLForIdArray(trailersToDelete));
            dataMiner.AddParameter(command, "ReturnValue", DbType.Int32, 0, ParameterDirection.ReturnValue, null);
            dataMiner.Execute(command, out count);

            return (int)CommonUtility.FilterNull(count, typeof(int));
        }

        public static int UpdateActiveTrailer(List<int> activeTrailers, List<int> inactiveTrailers)
        {
            object count = null;
            DataMiner dataMiner = DataFactory.GetDataMiner();
            DbCommand command = DataFactory.GetCommand();
            command.CommandText = "CSP_UpdateActiveTrailer";
            dataMiner.AddParameter(command, "@TrailerIdsToActive", DbType.String, -1, ParameterDirection.Input, DataMiner.FormatXMLForIdArray(activeTrailers));
            dataMiner.AddParameter(command, "@TrailerIdsToInactive", DbType.String, -1, ParameterDirection.Input, DataMiner.FormatXMLForIdArray(inactiveTrailers));
            dataMiner.AddParameter(command, "ReturnValue", DbType.Int32, 0, ParameterDirection.ReturnValue, null);
            dataMiner.Execute(command, out count);

            return (int)CommonUtility.FilterNull(count, typeof(int));
        }

        public static DataTable GetAllTrailers(int currentPageIndex, string sortOrder,
            int pageSize, string searchTitle, string searchGameTitle, DateTime? searchCreateDateFrom,
            DateTime? searchCreateDateTo, bool? searchActive, out int totalData)
        {
            totalData = 0;
            object count = null;

            DataMiner dataMiner = DataFactory.GetDataMiner();
            DbCommand command = DataFactory.GetCommand();

            dataMiner.AddParameter(command, "@CurrentPageIndex", DbType.Int32, 0, ParameterDirection.Input, currentPageIndex);
            dataMiner.AddParameter(command, "@SortOrder", DbType.String, 500, ParameterDirection.Input, sortOrder);
            dataMiner.AddParameter(command, "@PageSize", DbType.Int32, 0, ParameterDirection.Input, pageSize);
            dataMiner.AddParameter(command, "@SearchTitle", DbType.String, 2000, ParameterDirection.Input, searchTitle);
            dataMiner.AddParameter(command, "@SearchGameTitle", DbType.String, 2000, ParameterDirection.Input, searchGameTitle);
            dataMiner.AddParameter(command, "@SearchCreateDateFrom", DbType.DateTime, 0, ParameterDirection.Input, searchCreateDateFrom);
            dataMiner.AddParameter(command, "@SearchCreateDateTo", DbType.DateTime, 0, ParameterDirection.Input, searchCreateDateTo);
            dataMiner.AddParameter(command, "@SearchActive", DbType.Boolean, 0, ParameterDirection.Input, searchActive);

            command.CommandText = "CSP_GetTotalTrailerCount";
            count = dataMiner.GetOneData(command);
            totalData = (int)CommonUtility.FilterNull(count, typeof(int));

            command.CommandText = "CSP_GetTrailerList";
            return dataMiner.GetListData(command);
        }

        public static DataTable GetAllTrailersByGameId(int currentPageIndex, string sortOrder, 
            int pageSize, int gameId, out int totalData)
        {
            totalData = 0;
            object count = null;

            DataMiner dataMiner = DataFactory.GetDataMiner();
            DbCommand command = DataFactory.GetCommand();

            dataMiner.AddParameter(command, "@CurrentPageIndex", DbType.Int32, 0, ParameterDirection.Input, currentPageIndex);
            dataMiner.AddParameter(command, "@SortOrder", DbType.String, 500, ParameterDirection.Input, sortOrder);
            dataMiner.AddParameter(command, "@PageSize", DbType.Int32, 0, ParameterDirection.Input, pageSize);
            dataMiner.AddParameter(command, "@GameId", DbType.String, 2000, ParameterDirection.Input, gameId);

            command.CommandText = "CSP_GetTotalTrailerByGameIdCount";
            count = dataMiner.GetOneData(command);
            totalData = (int)CommonUtility.FilterNull(count, typeof(int));

            command.CommandText = "CSP_GetTrailerListByGameId";
            return dataMiner.GetListData(command);
        }

        public static DataTable GetTrailerFileLocationsForDelete(List<int> trailersToDelete)
        {
            DataMiner dataMiner = DataFactory.GetDataMiner();
            DbCommand command = DataFactory.GetCommand();
            command.CommandText = "CSP_GetTrailerFileLocationsByIds";
            dataMiner.AddParameter(command, "@Ids", DbType.String, -1, ParameterDirection.Input, DataMiner.FormatXMLForIdArray(trailersToDelete));
            return dataMiner.GetListData(command);
        }

        public static DataTable GetTrailerById(int id)
        {
            DataMiner dataMiner = DataFactory.GetDataMiner();
            DbCommand command = DataFactory.GetCommand();
            command.CommandText = "CSP_GetTrailerById";
            dataMiner.AddParameter(command, "@TrailerId", DbType.Int32, 0, ParameterDirection.Input, id);
            return dataMiner.GetListData(command);
        }

        public static int UpdateTrailer(int id, string title, int gameId, string description,
            string fileUrl, string thumbnailImageUrl, string previewImageUrl, int width, int height, bool isActive)
        {
            object count = null;
            DataMiner dataMiner = DataFactory.GetDataMiner();
            DbCommand command = DataFactory.GetCommand();
            command.CommandText = "CSP_UpdateTrailer";
            dataMiner.AddParameter(command, "@TrailerId", DbType.Int32, 0, ParameterDirection.Input, id);
            dataMiner.AddParameter(command, "@Title", DbType.String, -1, ParameterDirection.Input, title);
            dataMiner.AddParameter(command, "@GameId", DbType.Int32, 0, ParameterDirection.Input, gameId);
            dataMiner.AddParameter(command, "@Description", DbType.String, -1, ParameterDirection.Input, description);
            dataMiner.AddParameter(command, "@FileUrl", DbType.String, -1, ParameterDirection.Input, fileUrl);
            dataMiner.AddParameter(command, "@ThumbnailImageUrl", DbType.String, -1, ParameterDirection.Input, thumbnailImageUrl);
            dataMiner.AddParameter(command, "@PreviewImageUrl", DbType.String, -1, ParameterDirection.Input, previewImageUrl);
            dataMiner.AddParameter(command, "@Width", DbType.Int32, 0, ParameterDirection.Input, width);
            dataMiner.AddParameter(command, "@Height", DbType.Int32, 0, ParameterDirection.Input, height);
            dataMiner.AddParameter(command, "@IsActive", DbType.Boolean, 0, ParameterDirection.Input, isActive);
            dataMiner.AddParameter(command, "ReturnValue", DbType.Int32, 0, ParameterDirection.ReturnValue, null);
            dataMiner.Execute(command, out count);

            return (int)CommonUtility.FilterNull(count, typeof(int));
        }

        /**************************************************************
         *      OtherResource items
         *************************************************************/
        public static int CreateNewOtherResource(string title, int gameId, string description,
            string fileUrl, bool isActive)
        {
            object id = null;
            DataMiner dataMiner = DataFactory.GetDataMiner();
            DbCommand command = DataFactory.GetCommand();
            command.CommandText = "CSP_CreateNewOtherResource";
            dataMiner.AddParameter(command, "@Title", DbType.String, 2000, ParameterDirection.Input, title);
            dataMiner.AddParameter(command, "@GameId", DbType.Int32, 0, ParameterDirection.Input, gameId);
            dataMiner.AddParameter(command, "@Description", DbType.String, -1, ParameterDirection.Input, description);
            dataMiner.AddParameter(command, "@FileUrl", DbType.String, -1, ParameterDirection.Input, fileUrl);
            dataMiner.AddParameter(command, "@IsActive", DbType.Boolean, 0, ParameterDirection.Input, isActive);
            dataMiner.AddParameter(command, "ReturnValue", DbType.Int32, 0, ParameterDirection.ReturnValue, null);
            dataMiner.Execute(command, out id);

            return (int)CommonUtility.FilterNull(id, typeof(int));
        }

        public static int DeleteOtherResources(List<int> trailersToDelete)
        {
            object count = null;
            DataMiner dataMiner = DataFactory.GetDataMiner();
            DbCommand command = DataFactory.GetCommand();
            command.CommandText = "CSP_DeleteOtherResources";
            dataMiner.AddParameter(command, "@Ids", DbType.String, -1, ParameterDirection.Input, DataMiner.FormatXMLForIdArray(trailersToDelete));
            dataMiner.AddParameter(command, "ReturnValue", DbType.Int32, 0, ParameterDirection.ReturnValue, null);
            dataMiner.Execute(command, out count);

            return (int)CommonUtility.FilterNull(count, typeof(int));
        }

        public static int UpdateActiveOtherResource(List<int> activeOtherResources, List<int> inactiveOtherResources)
        {
            object count = null;
            DataMiner dataMiner = DataFactory.GetDataMiner();
            DbCommand command = DataFactory.GetCommand();
            command.CommandText = "CSP_UpdateActiveOtherResource";
            dataMiner.AddParameter(command, "@OtherResourceIdsToActive", DbType.String, -1, ParameterDirection.Input, DataMiner.FormatXMLForIdArray(activeOtherResources));
            dataMiner.AddParameter(command, "@OtherResourceIdsToInactive", DbType.String, -1, ParameterDirection.Input, DataMiner.FormatXMLForIdArray(inactiveOtherResources));
            dataMiner.AddParameter(command, "ReturnValue", DbType.Int32, 0, ParameterDirection.ReturnValue, null);
            dataMiner.Execute(command, out count);

            return (int)CommonUtility.FilterNull(count, typeof(int));
        }

        public static DataTable GetAllOtherResources(int currentPageIndex, string sortOrder,
            int pageSize, string searchTitle, string searchGameTitle, DateTime? searchCreateDateFrom,
            DateTime? searchCreateDateTo, bool? searchActive, out int totalData)
        {
            totalData = 0;
            object count = null;

            DataMiner dataMiner = DataFactory.GetDataMiner();
            DbCommand command = DataFactory.GetCommand();

            dataMiner.AddParameter(command, "@CurrentPageIndex", DbType.Int32, 0, ParameterDirection.Input, currentPageIndex);
            dataMiner.AddParameter(command, "@SortOrder", DbType.String, 500, ParameterDirection.Input, sortOrder);
            dataMiner.AddParameter(command, "@PageSize", DbType.Int32, 0, ParameterDirection.Input, pageSize);
            dataMiner.AddParameter(command, "@SearchTitle", DbType.String, 2000, ParameterDirection.Input, searchTitle);
            dataMiner.AddParameter(command, "@SearchGameTitle", DbType.String, 2000, ParameterDirection.Input, searchGameTitle);
            dataMiner.AddParameter(command, "@SearchCreateDateFrom", DbType.DateTime, 0, ParameterDirection.Input, searchCreateDateFrom);
            dataMiner.AddParameter(command, "@SearchCreateDateTo", DbType.DateTime, 0, ParameterDirection.Input, searchCreateDateTo);
            dataMiner.AddParameter(command, "@SearchActive", DbType.Boolean, 0, ParameterDirection.Input, searchActive);

            command.CommandText = "CSP_GetTotalOtherResourceCount";
            count = dataMiner.GetOneData(command);
            totalData = (int)CommonUtility.FilterNull(count, typeof(int));

            command.CommandText = "CSP_GetOtherResourceList";
            return dataMiner.GetListData(command);
        }

        public static DataTable GetOtherResourceFileLocationsToForDelete(List<int> trailersToDelete)
        {
            DataMiner dataMiner = DataFactory.GetDataMiner();
            DbCommand command = DataFactory.GetCommand();
            command.CommandText = "CSP_GetOtherResourceFileLocationsByIds";
            dataMiner.AddParameter(command, "@Ids", DbType.String, -1, ParameterDirection.Input, DataMiner.FormatXMLForIdArray(trailersToDelete));
            return dataMiner.GetListData(command);
        }

        public static DataTable GetOtherResourceById(int id)
        {
            DataMiner dataMiner = DataFactory.GetDataMiner();
            DbCommand command = DataFactory.GetCommand();
            command.CommandText = "CSP_GetOtherResourceById";
            dataMiner.AddParameter(command, "@OtherResourceId", DbType.Int32, 0, ParameterDirection.Input, id);
            return dataMiner.GetListData(command);
        }

        public static int UpdateOtherResource(int id, string title, int gameId, string description,
            string fileUrl, bool isActive)
        {
            object count = null;
            DataMiner dataMiner = DataFactory.GetDataMiner();
            DbCommand command = DataFactory.GetCommand();
            command.CommandText = "CSP_UpdateOtherResource";
            dataMiner.AddParameter(command, "@OtherResourceId", DbType.Int32, 0, ParameterDirection.Input, id);
            dataMiner.AddParameter(command, "@Title", DbType.String, -1, ParameterDirection.Input, title);
            dataMiner.AddParameter(command, "@GameId", DbType.Int32, 0, ParameterDirection.Input, gameId);
            dataMiner.AddParameter(command, "@Description", DbType.String, -1, ParameterDirection.Input, description);
            dataMiner.AddParameter(command, "@FileUrl", DbType.String, -1, ParameterDirection.Input, fileUrl);
            dataMiner.AddParameter(command, "@IsActive", DbType.Boolean, 0, ParameterDirection.Input, isActive);
            dataMiner.AddParameter(command, "ReturnValue", DbType.Int32, 0, ParameterDirection.ReturnValue, null);
            dataMiner.Execute(command, out count);

            return (int)CommonUtility.FilterNull(count, typeof(int));
        }

        /**************************************************************
         *      Wallpaper items
         *************************************************************/
        public static DataTable GetAllWallpapers(int currentPageIndex, string sortOrder, 
            int pageSize, string searchTitle, string searchGameTitle, DateTime? searchCreateDateFrom, 
            DateTime? searchCreateDateTo, bool? searchActive, out int totalData)
        {
            totalData = 0;
            object count = null;

            DataMiner dataMiner = DataFactory.GetDataMiner();
            DbCommand command = DataFactory.GetCommand();

            dataMiner.AddParameter(command, "@CurrentPageIndex", DbType.Int32, 0, ParameterDirection.Input, currentPageIndex);
            dataMiner.AddParameter(command, "@SortOrder", DbType.String, 500, ParameterDirection.Input, sortOrder);
            dataMiner.AddParameter(command, "@PageSize", DbType.Int32, 0, ParameterDirection.Input, pageSize);
            dataMiner.AddParameter(command, "@SearchTitle", DbType.String, 2000, ParameterDirection.Input, searchTitle);
            dataMiner.AddParameter(command, "@SearchGameTitle", DbType.String, 2000, ParameterDirection.Input, searchGameTitle);
            dataMiner.AddParameter(command, "@SearchCreateDateFrom", DbType.DateTime, 0, ParameterDirection.Input, searchCreateDateFrom);
            dataMiner.AddParameter(command, "@SearchCreateDateTo", DbType.DateTime, 0, ParameterDirection.Input, searchCreateDateTo);
            dataMiner.AddParameter(command, "@SearchActive", DbType.Boolean, 0, ParameterDirection.Input, searchActive);

            command.CommandText = "CSP_GetTotalWallpaperCount";
            count = dataMiner.GetOneData(command);
            totalData = (int)CommonUtility.FilterNull(count, typeof(int));

            command.CommandText = "CSP_GetWallpaperList";
            return dataMiner.GetListData(command);
        }

        public static DataTable GetWallpaperById(int id)
        {
            DataMiner dataMiner = DataFactory.GetDataMiner();
            DbCommand command = DataFactory.GetCommand();
            command.CommandText = "CSP_GetWallpaperById";
            dataMiner.AddParameter(command, "@WallpaperId", DbType.Int32, 0, ParameterDirection.Input, id);
            return dataMiner.GetListData(command);
        }

        public static int CreateNewWallpaper(string title, int gameId, string description, 
            string thumbImageUrl, string defaultSizeName, string defaultSizeUrl, bool isActive)
        {
            object id = null;
            DataMiner dataMiner = DataFactory.GetDataMiner();
            DbCommand command = DataFactory.GetCommand();
            command.CommandText = "CSP_CreateNewWallpaper";
            dataMiner.AddParameter(command, "@Title", DbType.String, 2000, ParameterDirection.Input, title);
            dataMiner.AddParameter(command, "@GameId", DbType.Int32, 0, ParameterDirection.Input, gameId);
            dataMiner.AddParameter(command, "@Description", DbType.String, -1, ParameterDirection.Input, description);
            dataMiner.AddParameter(command, "@ThumbImageUrl", DbType.String, -1, ParameterDirection.Input, thumbImageUrl);
            dataMiner.AddParameter(command, "@DefaultSizeName", DbType.String, -1, ParameterDirection.Input, defaultSizeName);
            dataMiner.AddParameter(command, "@DefaultSizeUrl", DbType.String, -1, ParameterDirection.Input, defaultSizeUrl);
            dataMiner.AddParameter(command, "@IsActive", DbType.Boolean, 0, ParameterDirection.Input, isActive);
            dataMiner.AddParameter(command, "ReturnValue", DbType.Int32, 0, ParameterDirection.ReturnValue, null);
            dataMiner.Execute(command, out id);

            return (int)CommonUtility.FilterNull(id, typeof(int));
        }

        /**************************************************************
         *      WallpaperSize items
         *************************************************************/

        public static DataTable GetWallpaperSizesByWallpaperId(int wallpaperId)
        {
            DataMiner dataMiner = DataFactory.GetDataMiner();
            DbCommand command = DataFactory.GetCommand();
            command.CommandText = "CSP_GetWallpaperSizesByWallpaperId";
            dataMiner.AddParameter(command, "@WallpaperId", DbType.Int32, 0, ParameterDirection.Input, wallpaperId);
            return dataMiner.GetListData(command);
        }

        public static int CreateNewWallpaperSize(int wallpaperId, string sizeName, string sizeFileUrl)
        {
            object id = null;
            DataMiner dataMiner = DataFactory.GetDataMiner();
            DbCommand command = DataFactory.GetCommand();
            command.CommandText = "CSP_CreateNewWallpaperSize";
            dataMiner.AddParameter(command, "@SizeName", DbType.String, 500, ParameterDirection.Input, sizeName);
            dataMiner.AddParameter(command, "@WallpaperId", DbType.Int32, 0, ParameterDirection.Input, wallpaperId);
            dataMiner.AddParameter(command, "@SizeFileUrl", DbType.String, -1, ParameterDirection.Input, sizeFileUrl);
            dataMiner.AddParameter(command, "ReturnValue", DbType.Int32, 0, ParameterDirection.ReturnValue, null);

            dataMiner.Execute(command, out id);

            return (int)CommonUtility.FilterNull(id, typeof(int));
        }

        public static int UpdateWallpaper(int wallpaperId, string title, int gameId, string description, 
            string thumbImageUrl, string defaultSizeName, string defaultSizeUrl, bool isActive)
        {
            object count = null;
            DataMiner dataMiner = DataFactory.GetDataMiner();
            DbCommand command = DataFactory.GetCommand();
            command.CommandText = "CSP_UpdateWallpaper";
            dataMiner.AddParameter(command, "@WallpaperId", DbType.Int32, 0, ParameterDirection.Input, wallpaperId);
            dataMiner.AddParameter(command, "@Title", DbType.String, 2000, ParameterDirection.Input, title);
            dataMiner.AddParameter(command, "@GameId", DbType.Int32, 0, ParameterDirection.Input, gameId);
            dataMiner.AddParameter(command, "@Description", DbType.String, -1, ParameterDirection.Input, description);
            dataMiner.AddParameter(command, "@ThumbImageUrl", DbType.String, -1, ParameterDirection.Input, thumbImageUrl);
            dataMiner.AddParameter(command, "@DefaultSizeName", DbType.String, -1, ParameterDirection.Input, defaultSizeName);
            dataMiner.AddParameter(command, "@DefaultSizeUrl", DbType.String, -1, ParameterDirection.Input, defaultSizeUrl);
            dataMiner.AddParameter(command, "@IsActive", DbType.Boolean, 0, ParameterDirection.Input, isActive);
            dataMiner.AddParameter(command, "ReturnValue", DbType.Int32, 0, ParameterDirection.ReturnValue, null);
            dataMiner.Execute(command, out count);

            return (int)CommonUtility.FilterNull(count, typeof(int));
        }

        public static DataTable GetWallpaperFileLocationsForDelete(List<int> wallpapersToDelete)
        {
            DataMiner dataMiner = DataFactory.GetDataMiner();
            DbCommand command = DataFactory.GetCommand();
            command.CommandText = "CSP_GetWallpaperFileLocationsByIds";
            dataMiner.AddParameter(command, "@Ids", DbType.String, -1, ParameterDirection.Input, DataMiner.FormatXMLForIdArray(wallpapersToDelete));
            return dataMiner.GetListData(command);
        }

        public static DataTable GetWallpaperSizeById(int wallpaperSizeId)
        {
            DataMiner dataMiner = DataFactory.GetDataMiner();
            DbCommand command = DataFactory.GetCommand();
            command.CommandText = "CSP_GetWallpaperSizesById";
            dataMiner.AddParameter(command, "@WallpaperSizeId", DbType.Int32, 0, ParameterDirection.Input, wallpaperSizeId);
            return dataMiner.GetListData(command);
        }

        public static DataTable GetWallpaperSizeFileLocationsForDelete(List<int> wallpaperSizesToDelete)
        {
            DataMiner dataMiner = DataFactory.GetDataMiner();
            DbCommand command = DataFactory.GetCommand();
            command.CommandText = "CSP_GetWallpaperSizeFileLocationsByIds";
            dataMiner.AddParameter(command, "@Ids", DbType.String, -1, ParameterDirection.Input, DataMiner.FormatXMLForIdArray(wallpaperSizesToDelete));
            return dataMiner.GetListData(command);
        }

        public static int UpdateWallpaperSize(int wallpaperSizeId, string sizeName, string sizeFileUrl)
        {
            object count = null;
            DataMiner dataMiner = DataFactory.GetDataMiner();
            DbCommand command = DataFactory.GetCommand();
            command.CommandText = "CSP_UpdateWallpaperSize";
            dataMiner.AddParameter(command, "@WallpaperSizeId", DbType.Int32, 0, ParameterDirection.Input, wallpaperSizeId);
            dataMiner.AddParameter(command, "@SizeName", DbType.String, 500, ParameterDirection.Input, sizeName);
            dataMiner.AddParameter(command, "@SizeFileUrl", DbType.String, -1, ParameterDirection.Input, sizeFileUrl);
            dataMiner.AddParameter(command, "ReturnValue", DbType.Int32, 0, ParameterDirection.ReturnValue, null);
            dataMiner.Execute(command, out count);

            return (int)CommonUtility.FilterNull(count, typeof(int));
        }

        public static int GetWallpaperSizeCountBySizeName(string sizeName)
        {
            object count = null;
            DataMiner dataMiner = DataFactory.GetDataMiner();
            DbCommand command = DataFactory.GetCommand();
            command.CommandText = "CSP_GetWallpaperSizeCountBySizeName";
            dataMiner.AddParameter(command, "@SizeName", DbType.String, 500, ParameterDirection.Input, sizeName);
            count = dataMiner.GetOneData(command);

            return (int)CommonUtility.FilterNull(count, typeof(int));
        }

        public static int DeleteWallpaperSizes(List<int> wallpaperSizeIdsToDelete)
        {
            object count = null;
            DataMiner dataMiner = DataFactory.GetDataMiner();
            DbCommand command = DataFactory.GetCommand();
            command.CommandText = "CSP_DeleteWallpaperSize";
            dataMiner.AddParameter(command, "@Ids", DbType.String, -1, ParameterDirection.Input, DataMiner.FormatXMLForIdArray(wallpaperSizeIdsToDelete));
            dataMiner.AddParameter(command, "ReturnValue", DbType.Int32, 0, ParameterDirection.ReturnValue, null);
            dataMiner.Execute(command, out count);

            return (int)CommonUtility.FilterNull(count, typeof(int));
        }

        public static int DeleteWallpapers(List<int> wallpapersToDelete)
        {
            object count = null;
            DataMiner dataMiner = DataFactory.GetDataMiner();
            DbCommand command = DataFactory.GetCommand();
            command.CommandText = "CSP_DeleteWallpaper";
            dataMiner.AddParameter(command, "@Ids", DbType.String, -1, ParameterDirection.Input, DataMiner.FormatXMLForIdArray(wallpapersToDelete));
            dataMiner.AddParameter(command, "ReturnValue", DbType.Int32, 0, ParameterDirection.ReturnValue, null);
            dataMiner.Execute(command, out count);

            return (int)CommonUtility.FilterNull(count, typeof(int));
        }

        public static DataTable GetWallpaperSizeFileLocationsForDeleteByWallpaperId(List<int> wallpapersToDelete)
        {
            DataMiner dataMiner = DataFactory.GetDataMiner();
            DbCommand command = DataFactory.GetCommand();
            command.CommandText = "CSP_GetWallpaperSizeFileLocationsByWallpaperIds";
            dataMiner.AddParameter(command, "@Ids", DbType.String, -1, ParameterDirection.Input, DataMiner.FormatXMLForIdArray(wallpapersToDelete));
            return dataMiner.GetListData(command);
        }

        public static int UpdateActiveWallpaper(List<int> activeWallpapers, List<int> inactiveWallpapers)
        {
            object count = null;
            DataMiner dataMiner = DataFactory.GetDataMiner();
            DbCommand command = DataFactory.GetCommand();
            command.CommandText = "CSP_UpdateActiveWallpaper";
            dataMiner.AddParameter(command, "@WallpaperIdsToActive", DbType.String, -1, ParameterDirection.Input, DataMiner.FormatXMLForIdArray(activeWallpapers));
            dataMiner.AddParameter(command, "@WallpaperIdsToInactive", DbType.String, -1, ParameterDirection.Input, DataMiner.FormatXMLForIdArray(inactiveWallpapers));
            dataMiner.AddParameter(command, "ReturnValue", DbType.Int32, 0, ParameterDirection.ReturnValue, null);
            dataMiner.Execute(command, out count);

            return (int)CommonUtility.FilterNull(count, typeof(int));
        }

        public static DataTable GetAllWallpapersByGameId(int currentPageIndex, string sortOrder, int pageSize, 
            int gameId, out int totalData)
        {
            totalData = 0;
            object count = null;

            DataMiner dataMiner = DataFactory.GetDataMiner();
            DbCommand command = DataFactory.GetCommand();

            dataMiner.AddParameter(command, "@CurrentPageIndex", DbType.Int32, 0, ParameterDirection.Input, currentPageIndex);
            dataMiner.AddParameter(command, "@SortOrder", DbType.String, 500, ParameterDirection.Input, sortOrder);
            dataMiner.AddParameter(command, "@PageSize", DbType.Int32, 0, ParameterDirection.Input, pageSize);
            dataMiner.AddParameter(command, "@GameId", DbType.String, 2000, ParameterDirection.Input, gameId);

            command.CommandText = "CSP_GetTotalWallpaperByGameIdCount";
            count = dataMiner.GetOneData(command);
            totalData = (int)CommonUtility.FilterNull(count, typeof(int));

            command.CommandText = "CSP_GetWallpaperListByGameId";
            return dataMiner.GetListData(command);
        }

        /**************************************************************
         *      TrailerFormat items
         *************************************************************/

        public static int CreateNewTrailerFormat(int trailerId, string videoFormat, string fileUrl)
        {
            object id = null;
            DataMiner dataMiner = DataFactory.GetDataMiner();
            DbCommand command = DataFactory.GetCommand();
            command.CommandText = "CSP_CreateNewTrailerFormat";
            dataMiner.AddParameter(command, "@VideoFormat", DbType.String, 500, ParameterDirection.Input, videoFormat);
            dataMiner.AddParameter(command, "@TrailerId", DbType.Int32, 0, ParameterDirection.Input, trailerId);
            dataMiner.AddParameter(command, "@FileUrl", DbType.String, -1, ParameterDirection.Input, fileUrl);
            dataMiner.AddParameter(command, "ReturnValue", DbType.Int32, 0, ParameterDirection.ReturnValue, null);

            dataMiner.Execute(command, out id);

            return (int)CommonUtility.FilterNull(id, typeof(int));
        }

        public static DataTable GetTrailerFormatFileLocationsForDelete(List<int> trailerFormatsToDelete)
        {
            DataMiner dataMiner = DataFactory.GetDataMiner();
            DbCommand command = DataFactory.GetCommand();
            command.CommandText = "CSP_GetTrailerFormatFileLocationsByIds";
            dataMiner.AddParameter(command, "@Ids", DbType.String, -1, ParameterDirection.Input, DataMiner.FormatXMLForIdArray(trailerFormatsToDelete));
            return dataMiner.GetListData(command);
        }

        public static DataTable GetTrailerFormatById(int trailerFormatId)
        {
            DataMiner dataMiner = DataFactory.GetDataMiner();
            DbCommand command = DataFactory.GetCommand();
            command.CommandText = "CSP_GetTrailerFormatsById";
            dataMiner.AddParameter(command, "@TrailerFormatId", DbType.Int32, 0, ParameterDirection.Input, trailerFormatId);
            return dataMiner.GetListData(command);
        }

        public static int GetTrailerFormatCountByVideoFormat(string videoFormat)
        {
            object count = null;
            DataMiner dataMiner = DataFactory.GetDataMiner();
            DbCommand command = DataFactory.GetCommand();
            command.CommandText = "CSP_GetTrailerFormatCountBySizeName";
            dataMiner.AddParameter(command, "@SizeName", DbType.String, 500, ParameterDirection.Input, videoFormat);
            count = dataMiner.GetOneData(command);

            return (int)CommonUtility.FilterNull(count, typeof(int));
        }

        public static int DeleteTrailerFormats(List<int> trailerFormatIdsToDelete)
        {
            object count = null;
            DataMiner dataMiner = DataFactory.GetDataMiner();
            DbCommand command = DataFactory.GetCommand();
            command.CommandText = "CSP_DeleteTrailerFormat";
            dataMiner.AddParameter(command, "@Ids", DbType.String, -1, ParameterDirection.Input, DataMiner.FormatXMLForIdArray(trailerFormatIdsToDelete));
            dataMiner.AddParameter(command, "ReturnValue", DbType.Int32, 0, ParameterDirection.ReturnValue, null);
            dataMiner.Execute(command, out count);

            return (int)CommonUtility.FilterNull(count, typeof(int));
        }

        public static int UpdateTrailerFormat(int trailerFormatId, string videoFormat, string fileUrl)
        {
            object count = null;
            DataMiner dataMiner = DataFactory.GetDataMiner();
            DbCommand command = DataFactory.GetCommand();
            command.CommandText = "CSP_UpdateTrailerFormat";
            dataMiner.AddParameter(command, "@TrailerFormatId", DbType.Int32, 0, ParameterDirection.Input, trailerFormatId);
            dataMiner.AddParameter(command, "@VideoFormat", DbType.String, 50, ParameterDirection.Input, videoFormat);
            dataMiner.AddParameter(command, "@FileUrl", DbType.String, -1, ParameterDirection.Input, fileUrl);
            dataMiner.AddParameter(command, "ReturnValue", DbType.Int32, 0, ParameterDirection.ReturnValue, null);
            dataMiner.Execute(command, out count);

            return (int)CommonUtility.FilterNull(count, typeof(int));
        }

        public static DataTable GetTrailerFormatsByTrailerId(int trailerId)
        {
            DataMiner dataMiner = DataFactory.GetDataMiner();
            DbCommand command = DataFactory.GetCommand();
            command.CommandText = "CSP_GetTrailerFormatsByTrailerId";
            dataMiner.AddParameter(command, "@TrailerId", DbType.Int32, 0, ParameterDirection.Input, trailerId);
            return dataMiner.GetListData(command);
        }
    }
}
